/*!
 * extends by jQuery
 * Date: 2015-11-25
 */

jQuery.fn.extend({
	
	serializeUnNull: function() {
		return jQuery.param( this.serializeArrayUnNull() );
	},
	serializeArrayUnNull: function() {
		var _rCRLF = /\r?\n/g,
		_rcheckableType = (/^(?:checkbox|radio)$/i),
		_rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
		_rsubmittable = /^(?:input|select|textarea|keygen)/i;
		return this.map(function() {
			// Can add propHook for "elements" to filter or add form elements
			var elements = jQuery.prop( this, "elements" );
			return elements ? jQuery.makeArray( elements ) : this;
		})
		.filter(function() {
			var type = this.type;
			// Use .is(":disabled") so that fieldset[disabled] works
			return this.name && !jQuery( this ).is( ":disabled" ) &&
			_rsubmittable.test( this.nodeName ) && !_rsubmitterTypes.test( type ) &&
				( this.checked || !_rcheckableType.test( type ) );
		})
		.map(function( i, elem ) {
			var val = jQuery( this ).val();

			return val == null ?
				{ name: elem.name, value: null} :
				jQuery.isArray( val ) ?
					jQuery.map( val, function( val ) {
						return { name: elem.name, value: val.replace( _rCRLF, "\r\n" ) };
					}) :
					{ name: elem.name, value: val.replace( _rCRLF, "\r\n" ) };
		}).get();
	}
});